package cn.e4j.modular.api.controller;

import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.util.AppCxt;
import cn.e4j.core.util.DateUtils;
import cn.e4j.core.util.LocalDateUtils;
import cn.e4j.core.util.ToolUtil;
import cn.e4j.modular.api.service.*;
import cn.e4j.modular.api.util.CommonUtils;
import cn.e4j.modular.crm.entity.*;
import cn.e4j.modular.crm.mapper.GwaaTMapper;
import cn.e4j.modular.crm.mapper.GwafTMapper;
import cn.e4j.modular.crm.mapper.GwakTMapper;
import cn.e4j.modular.crm.mapper.GweaTMapper;
import cn.e4j.modular.system.entity.SysOrg;
import cn.e4j.modular.system.entity.SysUser;
import cn.e4j.modular.system.mapper.SysOrgMapper;
import cn.e4j.modular.system.service.impl.SystemServiceImpl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 意向商机询单 控制类
 * Created by shixc on 2018/4/28.
 */
@RestController
@RequestMapping("api/wx/gwat300")
public class Gwat300Controller {
    private static Logger logger = LoggerFactory.getLogger(Gwat300Controller.class);

    @Autowired
    Gwat300Service gwat300Service;

    @Autowired
    GwaaTMapper gwaaTMapper;

    @Autowired
    Gwat200Service gwat200Service;

    @Autowired
    SysOrgMapper sysOrgMapper;

    @Autowired
    GwakTMapper gwakTMapper;

    @Autowired
    GwafTMapper gwafTMapper;

    @Autowired
    GwaService gwaService;

    @Autowired
    GweService gweService;

    @Autowired
    GweaTMapper gweaTMapper;

    @Autowired
    Gwat161Service gwat161Service;

    @Autowired
    GwbService gwbService;

    @Autowired
    SystemServiceImpl systemService;


//    //获取产品分类 gwat100/getGwahData
//    //获取产品分类图片 gwat100/getGwamData
//    //获取产品系列 gwat100/getGwaoData
//    //获取产品信息 gwat100/getGwamPage
//
//    //获取产品介绍 gwat100/getGwamOther
//    //获取配置表信息 gwat100/getGwax
//    //获取产品属性特征值信息 gwat100/getCharacteristic
//    //获取产品评价信息 gwat100/getGwcw
//    //获取省 reg/getProvinces
//    //获取市 reg/getCitys
//    //获取县 reg/getDistricts
//    //获取线人信息 gwat200/getGwak
//    //校验客户手机号码  gwat100/checkCustomerPhone
//    //保存客户信息 gwat100/saveCustomer
//
    /**
     * 获取默认信息
     *
     * @return
     */
    @RequestMapping(value = "getinfo")
    public ResponseData getinfo(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        SysUser currentUser = wapper.getSysUser();
        try {
            inDto.put("GWCQUSER", currentUser.getID());
            list = gwat300Service.getinfo(inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error("服务器出小差了");
        }
        return new SuccessResponseData(list);
    }


    /**
     * 获取转单列表
     *
     * @return
     */
    @RequestMapping(value = "getGwcoData")
    public ResponseData getGwcoData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        int errcode = 200;
        String errmsg = "ok";
        List<Dto> list = new ArrayList<Dto>();
        SysUser user = wapper.getSysUser();
        try {
            QueryWrapper<GwaaT> wrapper = new QueryWrapper<>();
            wrapper.eq("GWAAENT", inDto.getString("ENT"));
            wrapper.eq("GWAA001", user.getACCOUNT());
            GwaaT gwaaT = gwaaTMapper.selectOne(wrapper);
            inDto.put("GWCOENT", inDto.getString("ENT"));
            inDto.put("GWAA003", user.getACCOUNT());
            //Dto dto = gwat300Service.getGwaa(inDto); //好像不是用这个判断
            if (gwaaT.getGWAA007().equals("0")) { //业务人员
                list = gwat300Service.getGwco1Data(wapper.getPage(),inDto);
            } else if (gwaaT.getGWAA007().equals("1")) { //经销商
                list = gwat300Service.getGwco2Data(wapper.getPage(),inDto);
            }
        } catch (Exception e) {
            errmsg = "服务器出小差了";
            e.printStackTrace();
            return ResponseData.error(errmsg);
        }
        return new SuccessResponseData(list);
    }

    /**
     * 转单--提交 remove
     *
     * @return
     */
//    @RequestMapping(value = "zdSubmit")
//    public ResponseData updateY(@DtoParam DtoWapper wapper) {
//        Date date = new Date();
//        Dto inDto = wapper.getDto();
//        Dto outDto = new Dto();
//
//        List<GwcqT> gwcq_tPOs = new ArrayList<>();
//        List<GwcoT> gwco_tPOs = new ArrayList<>();
//        try {
//            SysUser currentUser = wapper.getSysUser();
//            JSONArray orders = JSONArray.parseArray(inDto.getString("objs"));
//            String no = "GWDD" + DateUtils.getDate("yyyyMMddHHmmssSSS");
//            for (int i = 0, j = orders.size(); i < j; i++) {
//                JSONObject item = orders.getJSONObject(i);
//                GwcqT gwcq_tPO = new GwcqT();
//                gwcq_tPO.setGWCQENT(currentUser.getDBC());
//                gwcq_tPO.setGWCQDOCNO(no);
//                gwcq_tPO.setGWCQSEQ(BigDecimal.valueOf(i + 1));
//                gwcq_tPO.setGWCQDOCDATE(LocalDate.now());
//                gwcq_tPO.setGWCQ001(item.getString("GWCO001"));
//                gwcq_tPO.setGWCQ002(item.getString("GWCO002")); // 销售单位
//                gwcq_tPO.setGWCQ003(item.getBigDecimal("GWCO003"));
//                gwcq_tPO.setGWCQ004(item.getBigDecimal("GWCO004"));
//                gwcq_tPO.setGWCQ005(item.getBigDecimal("GWCO003").multiply(item.getBigDecimal("gwco004")));
//                gwcq_tPO.setGWCQ006(item.getString("GWCO006"));
//                gwcq_tPO.setGWCQ007(item.getString("GWCO007"));
//                gwcq_tPO.setGWCQ008(item.getString("GWCO008"));
//                gwcq_tPO.setGWCQ009(item.getString("GWCO009"));
//                gwcq_tPO.setGWCQ010(item.getString("GWCO010"));
//                gwcq_tPO.setGWCQ011(item.getString("GWCO011"));
//                gwcq_tPO.setGWCQ012(item.getString("GWCO012"));
//                gwcq_tPO.setGWCQ013(item.getString("GWCO013"));
//                if (item.containsKey("GWCQ016") && !item.getString("GWCQ016").equals("")) {
//                    gwcq_tPO.setGWCQ016(LocalDateUtils.dateToLocalDate(DateUtils.parseDate(item.getString("GWCQ016"))));
//                }
//
//                gwcq_tPO.setGWCQ013(item.getString("GWCO013"));
//                gwcq_tPO.setGWCQ020(item.getString("GWCO020"));
//                gwcq_tPO.setGWCQ021(item.getString("GWCO021"));
//                gwcq_tPO.setGWCQ022(item.getString("GWCO022"));
//                gwcq_tPO.setGWCQ023(item.getString("GWCO023"));
//                gwcq_tPO.setGWCQ024(item.getString("GWCO024"));
//                gwcq_tPO.setGWCQ025(item.getString("GWCO025"));
//                gwcq_tPO.setGWCQ026(item.getString("GWCO026"));
//                gwcq_tPO.setGWCQ027(item.getString("GWCO027"));
//                gwcq_tPO.setGWCQ028(item.getString("GWCO028"));
//                gwcq_tPO.setGWCQ030(item.getString("GWCODOCNO"));
//                gwcq_tPO.setGWCQ031(item.getBigDecimal("GWCOSEQ"));
//                gwcq_tPO.setGWCQ060(item.getString("GWCQ060"));
//                gwcq_tPO.setGWCQ061(item.getString("GWCQ061"));
//                gwcq_tPO.setGWCQACTI("Y");
//                gwcq_tPO.setGWCQUSER(currentUser.getID());
//                gwcq_tPO.setGWCQGRUP(currentUser.getORG_ID());
//                gwcq_tPO.setGWCQTIME(DateUtils.formatDate(date, DateUtils.PATTERN_HH_mm_ss));
//                gwcq_tPO.setGWCQDATE(LocalDate.now());
//                gwcq_tPO.setGWCQORIU(currentUser.getID());
//                gwcq_tPO.setGWCQORIG(currentUser.getORG_ID());
//                gwcq_tPOs.add(gwcq_tPO);
//
//                GwcoT gwco_tPO = new GwcoT();
//                gwco_tPO.setGWCOENT(currentUser.getDBC());
//                gwco_tPO.setGWCODOCNO(item.getString("GWCODOCNO"));
//                gwco_tPO.setGWCOSEQ(item.getBigDecimal("GWCOSEQ"));
//                gwco_tPO.setGWCOACTI("Z");
//                gwco_tPO.setGWCOORIU(currentUser.getID());
//                gwco_tPOs.add(gwco_tPO);
//            }
//            gwat300Service.saveData(gwcq_tPOs, gwco_tPOs);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return new ErrorResponseData("服务开小差了");
//        }
//        return new SuccessResponseData();
//    }

    /**
     * 取消转单
     *
     * @return
     */
    @RequestMapping(value = "updateN")
    public ResponseData updateN(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto nos = new Dto();
        nos.put("count1", 0);
        nos.put("count2", 0);
        try {

            JSONObject inJson = JSONObject.parseObject(inDto.getString("obj"));
            JSONArray orders = inJson.getJSONArray("orders");
            Dto sDto = new Dto();

            JSONObject item = orders.getJSONObject(0);

            String GWBKNAME_ = item.getString("GWBKNAME");
            Dto gwcoDto = new Dto();
            gwcoDto.put("GWCODOCNO", GWBKNAME_);
            Dto countDto = gwat200Service.getGwco(gwcoDto);

            if (countDto.getInteger("COUNT") == 0) {
                //sDto.put("GWBKNAME", GWBKNAME_);
                //sDto.put("GWBKID", item.getString("GWBKID"));
                //sDto.put("GWBKSEQ2", item.getString("GWBKSEQ2"));
                //sDto.put("GWBKSEQ", item.getString("GWBKSEQ"));
                //sDto.put("gwbkacti", "Y");
                //sDto.put("gwbkoriu", currentUser.getId_());

                Dto gwcqDto = new Dto();
                gwcqDto.put("GWCQ030", GWBKNAME_);
                Dto gwcqCount = gwat300Service.getGwcqByZ(gwcqDto);

                if (gwcqCount.getInteger("COUNT") == 0) {
                    // 取消转单则自动删除状态为“S.已成交”的拜访记录
                    Dto gwbhDto = new Dto();
                    gwbhDto.put("GWBHENT", inDto.getString("ENT"));
                    gwbhDto.put("GWBHNAME", GWBKNAME_);
                    gwbhDto.put("GWBHID", item.getString("GWBKID"));
                    gwbhDto.put("GWBHSEQ", item.getString("GWBKSEQ2"));
                    gwat300Service.cancelZd(sDto, gwbhDto);


                } else {
                    nos.put("count2", gwcqCount.getInteger("COUNT"));
                }
            } else {
                nos.put("count1", countDto.getInteger("COUNT"));
            }

        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error("服务器开小差了");
        }
        return new SuccessResponseData(nos);
    }

    /**
     * 转单--数据修改
     *
     * @return
     */
    @RequestMapping(value = "zdSave")
    public ResponseData zdSave(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto outDto = new Dto();
        SysUser currentUser = wapper.getSysUser();
        List<GwcoT> gwco_tPOs = new ArrayList<>();
        try {
            JSONObject inJson = JSONObject.parseObject(inDto.getString("obj"));

            JSONArray orders = inJson.getJSONArray("orders");
            for (int i = 0, j = orders.size(); i < j; i++) {
                JSONObject item = orders.getJSONObject(i);
                GwcoT gwco_tPO =  CommonUtils.toJavaClass(item, GwcoT.class);

                gwco_tPO.setGWCOENT(currentUser.getDBC());
                //gwco_tPO.setGwco001(gwan001Dto.get(0).getString("gwan001"));// 设置成子料号
                gwco_tPO.setGWCO005(gwco_tPO.getGWCO003().multiply(gwco_tPO.getGWCO004()));
                gwco_tPO.setGWCOMODU(currentUser.getNAME());
                gwco_tPOs.add(gwco_tPO);
            }

            gwat300Service.updateGwco(gwco_tPOs);
            outDto.put("data", gwco_tPOs);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error("服务开小差了");
        }
        return new SuccessResponseData();
    }

    /**
     * 购物车--添加
     *
     * @return
     */
    @RequestMapping(value = "addCartData")
    public ResponseData addCartData(@DtoParam DtoWapper wapper) {
        Date date = new Date();
        Dto inDto = wapper.getDto();
        Dto outDto = new Dto();
        SysUser currentUser = wapper.getSysUser();
        GwcqT gwcq_tPO = new GwcqT();
        List<GwcqT> gwcq_tPOs = new ArrayList<>();
        try {

            JSONObject inJson = JSONObject.parseObject(inDto.getString("obj"));
            gwcq_tPO = CommonUtils.toJavaClass(inJson,GwcqT.class);
            gwcq_tPO.setGWCQENT(currentUser.getDBC());
            gwcq_tPO.setGWCQDOCNO("GWDD" + DateUtils.getDate("yyyyMMddHHmmssSSS"));
            gwcq_tPO.setGWCQSEQ(BigDecimal.ONE);
            gwcq_tPO.setGWCQDOCDATE(LocalDate.now());

            gwcq_tPO.setGWCQ005(gwcq_tPO.getGWCQ003().multiply(gwcq_tPO.getGWCQ004()));

            gwcq_tPO.setGWCQ014(currentUser.getID());
            gwcq_tPO.setGWCQACTI("Y");
            gwcq_tPO.setGWCQUSER(currentUser.getID());
            gwcq_tPO.setGWCQGRUP(currentUser.getORG_ID());
            gwcq_tPO.setGWCQTIME(DateUtils.formatDate(date, DateUtils.PATTERN_HH_mm_ss));
            gwcq_tPO.setGWCQDATE(LocalDate.now());
            gwcq_tPO.setGWCQORIU(currentUser.getID());
            gwcq_tPO.setGWCQORIG(currentUser.getORG_ID());
            gwcq_tPOs.add(gwcq_tPO);
            gwat300Service.saveData(gwcq_tPOs, new ArrayList<GwcoT>());
            outDto.put("GWCQDOCNO", gwcq_tPO.getGWCQDOCNO());
            outDto.put("GWCQSEQ", gwcq_tPO.getGWCQSEQ());
        } catch (Exception e) {
            e.printStackTrace();
            outDto.setAppCode(500);
            return new ErrorResponseData("服务开小差了");
        }
        return new SuccessResponseData(outDto);
    }
//
    /**
     * 获取购物车信息
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getGwcqData")
    public ResponseData getGwcqData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser user = wapper.getSysUser();

        inDto.put("GWCQUSER", user.getID());
        List<Dto> list = gwat300Service.getGwcqData(wapper.getPage(),inDto);

        return new SuccessResponseData(list);
    }

    /**
     * 购物车更新数量
     *
     * @return
     */
    @RequestMapping(value = "updateGwcq")
    public ResponseData updateGwcq(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto outDto = new Dto();
        List<GwcqT> gwcq_tPOs = new ArrayList<>();
        SysUser user = wapper.getSysUser();
        try {
            JSONObject inJson = JSONObject.parseObject(inDto.getString("obj"));
            JSONArray orders = inJson.getJSONArray("orders");
            for (int i = 0, j = orders.size(); i < j; i++) {
                JSONObject item = orders.getJSONObject(i);
                GwcqT gwcq_tPO = new GwcqT();
                gwcq_tPO.setGWCQENT(item.getString("GWCQENT"));
                gwcq_tPO.setGWCQDOCNO(item.getString("GWCQDOCNO"));
                gwcq_tPO.setGWCQSEQ(item.getBigDecimal("GWCQSEQ"));
                gwcq_tPO.setGWCQ030(item.getString("GWCQ030"));
                gwcq_tPO.setGWCQ031(item.getBigDecimal("GWCQ031"));
                gwcq_tPO.setGWCQ003(item.getBigDecimal("GWCQ003"));
                gwcq_tPO.setGWCQ005(item.getBigDecimal("GWCQ003").multiply(item.getBigDecimal("GWCQ004")));
                gwcq_tPOs.add(gwcq_tPO);
            }
            gwat300Service.updateGwcq(gwcq_tPOs);
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("服务开小差了");
        }
        return new SuccessResponseData();
    }

    /**
     * 下单存入更新
     *
     * @return
     */
    @RequestMapping(value = "updateData")
    public ResponseData updateData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<GwcsT> gwcs_tPOs = new ArrayList<>();
        List<GwcqT> gwcq_tPOs = new ArrayList<>();
        SysUser user = wapper.getSysUser();
        Date date = new Date();
        String docno = "ZS" + DateUtils.getDate("yyyyMMddHHmmssSSS");
        JSONObject inJson = new JSONObject();
        JSONArray orders = new JSONArray();
        try {
            inJson = JSONObject.parseObject(inDto.getString("obj"));


            //add by wenchuan.li 2018/10/30 17:29
            // 添加法人、Erp归属组织
            String gwcslegal = inJson.getString("GWCSLEGAL");//归属法人
            if (ToolUtil.isNotEmpty(gwcslegal)) {
                SysOrg sys_org = sysOrgMapper.selectById(gwcslegal);

                // 取折扣率
                // GWAK056为空 就取 客户分类表的折扣率，如果没有就默认1
                QueryWrapper<GwakT> wrapper = new QueryWrapper<>();
                wrapper.eq("GWAKENT",inDto.getString("ENT"));
                wrapper.eq("GWAK001",inJson.getString("GWCS011"));
                GwakT gwak_tPO = gwakTMapper.selectOne(wrapper);//取经销商 20190201
                BigDecimal GWCS035 = BigDecimal.ONE;
                if (ToolUtil.isNotEmpty(gwak_tPO)) {
                    if (gwak_tPO.getGWAK056() == null) {
                        String GWAK009 = gwak_tPO.getGWAK009();
                        if (ToolUtil.isNotEmpty(GWAK009) && !GWAK009.equals("*")) {
                            QueryWrapper<GwafT> gwafTQueryWrapper = new QueryWrapper<>();
                            gwafTQueryWrapper.eq("GWAFENT",inDto.getString("ENT"));
                            gwafTQueryWrapper.eq("GWAF001",GWAK009);
                            GwafT gwaf_tPO = gwafTMapper.selectOne(gwafTQueryWrapper);
                            if (gwaf_tPO != null && gwaf_tPO.getGWAF004() != null) {
                                GWCS035 = new BigDecimal(gwaf_tPO.getGWAF004());
                            }
                        }
                    } else {
                        GWCS035 = gwak_tPO.getGWAK056();
                    }
                }

                //币别表获取 金额保留小数
                Dto dto = new Dto();
                dto.put("GWAC001", gwak_tPO.getGWAK008());
                dto.put("GWACENT", inDto.getString("ENT"));
                Dto gwac = gwaService.getGwa001(dto);
                int GWAC002 = 2;
                if (ToolUtil.isNotEmpty(gwac)) {
                    GWAC002 = gwac.getBigDecimal("GWAC002").intValue();
                }

                if (ToolUtil.isNotEmpty(GWAC002)) {
                    GWAC002 = 2;
                }

                orders = inJson.getJSONArray("orders");
                for (int i = 0, j = orders.size(); i < j; i++) {
                    JSONObject item = orders.getJSONObject(i);
                    GwcsT gwcs_tPO = CommonUtils.toJavaClass(inJson,GwcsT.class);
                    gwcs_tPO.setGWCSENT(user.getDBC());
                    gwcs_tPO.setGWCSDOCNO(docno);
                    gwcs_tPO.setGWCSSEQ(BigDecimal.valueOf(i + 1));
                    gwcs_tPO.setGWCS030(item.getString("GWCQDOCNO"));
                    gwcs_tPO.setGWCS031(item.getBigDecimal("GWCQSEQ"));

                    gwcs_tPO.setGWCSDOCDATE(LocalDate.now());
                    gwcs_tPO.setGWCS001(item.getString("GWCQ001"));
                    gwcs_tPO.setGWCS002(item.getString("GWCQ002"));
                    gwcs_tPO.setGWCS003(item.getBigDecimal("GWCQ003"));
                    gwcs_tPO.setGWCS004(item.getBigDecimal("GWCQ004"));
                    gwcs_tPO.setGWCS005(gwcs_tPO.getGWCS003().multiply(gwcs_tPO.getGWCS004()));

                    //转单的必须是指派的经销商
                    gwcs_tPO.setGWCS011(inJson.getString("GWCS011"));
                    gwcs_tPO.setGWCS012(inJson.getString("GWCS012"));
                    gwcs_tPO.setGWCS013(inJson.getString("GWCS013"));
//                    gwcs_tPO.setGWCS014(item.getString("GWCQ014"));
                    gwcs_tPO.setGWCS014(user.getID());
                    //}

                    //add by wenchuan.li 2018/10/30 17:29
//                    gwcs_tPO.setGWCS006(gwak_tPO.getGWAK008());//交易币别
                    if (ToolUtil.isNotEmpty(sys_org)) {
                        gwcs_tPO.setGWCSLEGAL(sys_org.getBIZ_CODE());//erp所属法人组织
                    }
                    gwcs_tPO.setGWCSMLEGAL(gwcslegal);//所属法人

                    //add by wenchuan.li 2018/10/31 12:46
//                    gwcs_tPO.setGWCS032(gwak_tPO.getGWAK012());//税种
//                    gwcs_tPO.setGWCS033(gwak_tPO.getGWAK057());//汇率类型

//                    if ("1".equals(gwcs_tPO.getGWCS033())) {
//                        Dto dto1 = new Dto();
//                        dto1.put("GWEK001", gwcs_tPO.getGWCS006());
//                        dto1.put("ENT", inDto.getString("ENT"));
//                        Dto gwek = gweService.getGwe001(dto1);
//                        if (ToolUtil.isNotEmpty(gwek)) {
//                            gwcs_tPO.setGWCS034(gwek.getBigDecimal("GWEK004"));//汇率
//                        }
//                    } else if ("2".equals(gwcs_tPO.getGWCS033())) {
//                        Dto dto1 = new Dto();
//                        dto1.put("GWEL001", gwcs_tPO.getGWCS006());
//                        dto1.put("ENT", inDto.getString("ENT"));
//                        Dto gwel = gweService.getGwe002(dto1);
//                        if (ToolUtil.isNotEmpty(gwel)) {
//                            gwcs_tPO.setGWCS034(gwel.getBigDecimal("GWEL004"));//汇率
//                        }
//                    }
                    //*********更新存值 20191108 by caijy***********
                    //查询客户
                    GwakT gwakT = new GwakT().selectById(gwcs_tPO.getGWCS010());
                    gwcs_tPO.setGWCSPLANT(gwakT==null?"":gwakT.getGWAKPLANT());//根据客户默认抓取gwakPLANT

                    BigDecimal GWCS115=null;//结算价
                    if (gwakT!=null){
                        String gwak061 = gwakT.getGWAK061();
                        String gwak058 = gwakT.getGWAK058();

                        if (gwak061!=null){
                            if (gwakT.getGWAK061().equals("Y"))
                                GWCS115 = gwcs_tPO.getGWCS004().multiply(gwakT.getGWAK062().add(BigDecimal.valueOf(1)));
                            else
                                GWCS115 = gwcs_tPO.getGWCS004();
                        }
                        gwcs_tPO.setGWCS113(gwak058==null?" ":gwak058);//发货仓库
                        gwcs_tPO.setGWCS118(gwak061==null?"*":gwak061);//拆包否

                        //GWCS006 ：客户资料上gwak008
                        gwcs_tPO.setGWCS006(gwakT.getGWAK008());
                        //汇率类型gwcs033默认取客户资料gwak057
                        gwcs_tPO.setGWCS032(gwakT.getGWAK012());//税种

                        String gwak057 = gwakT.getGWAK057();
                        if (gwak057==null){
                            gwcs_tPO.setGWCS033(AppCxt.getParam("change_rate_type_"));
                        }else
                            gwcs_tPO.setGWCS033(gwak057);//汇率类型


                        if ("1".equals(gwcs_tPO.getGWCS033())) {
                            Dto dto1 = new Dto();
                            dto1.put("GWEK001", gwcs_tPO.getGWCS006());
                            dto1.put("ENT", inDto.getString("ENT"));
                            Dto gwek = gweService.getGwe001(dto1);
                            if (ToolUtil.isNotEmpty(gwek)) {
                                gwcs_tPO.setGWCS034(gwek.getBigDecimal("GWEK004"));//汇率
                            }
                        } else if ("2".equals(gwcs_tPO.getGWCS033())) {
                            Dto dto1 = new Dto();
                            dto1.put("GWEL001", gwcs_tPO.getGWCS006());
                            dto1.put("ENT", inDto.getString("ENT"));
                            Dto gwel = gweService.getGwe002(dto1);
                            if (ToolUtil.isNotEmpty(gwel)) {
                                gwcs_tPO.setGWCS034(gwel.getBigDecimal("GWEL004"));//汇率
                            }
                        }

                        GweaT gweaT = new GweaT().selectById(gwcs_tPO.getGWCS032());

                        if (gweaT!= null){
                            BigDecimal gwea006 = gweaT.getGWEA006();

                            //gwcs005含税金额=gwcs003*gwcs004
                            //税额gwcs040=gwcs005-(gwcs005/(1+gwea006/100)
                            BigDecimal gwcs005 = gwcs_tPO.getGWCS005();
                            BigDecimal GWCS040 = gwcs005.subtract(gwcs005.divide(BigDecimal.valueOf(1).add(gwea006.divide(BigDecimal.valueOf(100))),4,BigDecimal.ROUND_HALF_UP)).setScale(GWAC002, BigDecimal.ROUND_HALF_UP);
                            //gwcs041=gwcs040/(1+gwcs034/100)
                            if (gwcs_tPO.getGWCS034() == null) {
                                gwcs_tPO.setGWCS034(BigDecimal.ONE);//汇率
                            }
                            BigDecimal GWCS041 = GWCS040.divide(BigDecimal.valueOf(1).add(gwcs_tPO.getGWCS034().divide(BigDecimal.valueOf(100))),4,BigDecimal.ROUND_HALF_UP).setScale(GWAC002, BigDecimal.ROUND_HALF_UP);

                            gwcs_tPO.setGWCS040(GWCS040);
                            gwcs_tPO.setGWCS041(GWCS041);
                        }

                    }
                    //*********更新存值 20191108 by caijy***********

                    gwcs_tPO.setGWCS035(GWCS035);//折扣
                    gwcs_tPO.setGWCS036(GWCS035.multiply(gwcs_tPO.getGWCS005()).setScale(GWAC002, BigDecimal.ROUND_HALF_UP));//原币折扣后金额

                    if (gwcs_tPO.getGWCS034()!=null){
                        //原币含税折扣价
                        gwcs_tPO.setGWCS037(gwcs_tPO.getGWCS004().divide(gwcs_tPO.getGWCS034()).setScale(GWAC002));
                        //本币单价
                        gwcs_tPO.setGWCS038(gwcs_tPO.getGWCS037().multiply(gwcs_tPO.getGWCS003()).setScale(GWAC002, BigDecimal.ROUND_HALF_UP));
                        //本币含税金额
                        gwcs_tPO.setGWCS039(gwcs_tPO.getGWCS038().multiply(gwcs_tPO.getGWCS035()).setScale(GWAC002, BigDecimal.ROUND_HALF_UP));
                    }

//                    if (ToolUtil.isNotEmpty(gwak_tPO.getGWAK012()) && !gwak_tPO.getGWAK012().equals("NULL")) {
//
//                        QueryWrapper<GweaT> queryWrapper = new QueryWrapper<>();
//                        queryWrapper.eq("GWEA001",gwak_tPO.getGWAK012());
//                        GweaT gwea_tPO = gweaTMapper.selectOne(queryWrapper);
//                        gwea_tPO.setGWEA006(gwea_tPO.getGWEA006().divide(BigDecimal.valueOf(100), BigDecimal.ROUND_HALF_UP).setScale(8));
//                        if (ToolUtil.isNotEmpty(gwea_tPO)) {
//
//                            //select gwea006（税率），gwea007（含税否） from gwea_t where gwea001=税种（GWAK012）
//                            //再判断gwea007的值，如果gwea007=‘Y’， 那么wcs040=GWCS036*gwea006/（1+gwea006），GWCS041=GWCS039*gwea006（1+gwea006）；如果gwea007=‘N’， 那么wcs040=GWCS036*gwea006，GWCS041=GWCS039*gwea006
//                            if (gwea_tPO.getGWEA007().equals("Y")) {
//                                gwcs_tPO.setGWCS040(gwcs_tPO.getGWCS036().multiply(gwea_tPO.getGWEA006()).divide(gwea_tPO.getGWEA006().add(BigDecimal.ONE), BigDecimal.ROUND_HALF_UP).setScale(GWAC002, BigDecimal.ROUND_HALF_UP));
//                                gwcs_tPO.setGWCS041(gwcs_tPO.getGWCS039().multiply(gwea_tPO.getGWEA006()).divide(gwea_tPO.getGWEA006().add(BigDecimal.ONE), BigDecimal.ROUND_HALF_UP).setScale(GWAC002, BigDecimal.ROUND_HALF_UP));
//                            } else {
//                                gwcs_tPO.setGWCS040(gwcs_tPO.getGWCS036().multiply(gwea_tPO.getGWEA006()).setScale(GWAC002, BigDecimal.ROUND_HALF_UP));
//                                gwcs_tPO.setGWCS041(gwcs_tPO.getGWCS039().multiply(gwea_tPO.getGWEA006()).setScale(GWAC002, BigDecimal.ROUND_HALF_UP));
//                            }
//
//                        }
//                    }

                    Dto gwalListDto = Dtos.newDto();
                    gwalListDto.put("GWALENT", inDto.getString("ENT"));
                    gwalListDto.put("GWAL001", gwcs_tPO.getGWCS011());
                    List<Dto> gwalList = gwat300Service.getGwalList(gwalListDto);
                    for (Dto gwalitem : gwalList) {

                        if (gwalitem.getString("GWAL003").equals("I")) {
                            //发票寄送地址
                            gwcs_tPO.setGWCS106(gwalitem.getString("GWAL018"));
                            gwcs_tPO.setGWCS105(gwalitem.getString("GWAL021"));
                            gwcs_tPO.setGWCS103(gwalitem.getString("GWAL020"));
                        }
                    }
                    //送货地址根据客户编号
                    gwalListDto.put("GWAL001", gwcs_tPO.getGWCS010());
                    List<Dto> gwal = gwat300Service.getGwalList(gwalListDto);
                    for (Dto gwalitem : gwal) {
                        if (gwalitem.getString("GWAL003").equals("D")) {
                            //发票寄送地址
                            gwcs_tPO.setGWCS020(gwalitem.getString("GWAL018"));
                            gwcs_tPO.setGWCS008(gwalitem.getString("GWAL021"));
                            gwcs_tPO.setGWCS009(gwalitem.getString("GWAL020"));
                        }
                    }
                    gwcs_tPO.setGWCSACTI("N");
                    gwcs_tPO.setGWCSDATE(LocalDate.now());
                    gwcs_tPO.setGWCSORIG(user.getORG_ID());
                    gwcs_tPO.setGWCSUSER(user.getID());

                    //*********更新存值 20191108 by caijy***********

                    gwcs_tPO.setGWCS112("1");//协议仓库类型,默认1总部仓
                    gwcs_tPO.setGWCS115(GWCS115);
                    gwcs_tPO.setGWCS117("1");
                    gwcs_tPO.setGWCS119("1");
                    //*********更新存值 20191108 by caijy***********
                    gwcs_tPOs.add(gwcs_tPO);

                    GwcqT gwcq_tPO = new GwcqT();
                    gwcq_tPO.setGWCQENT(user.getDBC());
                    gwcq_tPO.setGWCQDOCNO(item.getString("GWCQDOCNO"));
                    gwcq_tPO.setGWCQSEQ(item.getBigDecimal("GWCQSEQ"));
                    gwcq_tPO.setGWCQ030(item.getString("GWCQ030"));
                    gwcq_tPO.setGWCQ031(item.getBigDecimal("GWCQ031"));
                    gwcq_tPO.setGWCQACTI("Z");
                    gwcq_tPOs.add(gwcq_tPO);
                }
                gwat300Service.insert(gwcs_tPOs, gwcq_tPOs);
            } else {
                return new ErrorResponseData("法人不可为空");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("系统出小差了");
        }

        return ResponseData.success();
    }

    /**
     * 获取客户信息
     *
     * @return
     */
    @RequestMapping(value = "getGwakData")
    public ResponseData getGwakData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        SysUser user = wapper.getSysUser();
        try {
            QueryWrapper<GwaaT> wrapper = new QueryWrapper<>();
            wrapper.eq("GWAAENT", inDto.getString("ENT"));
            wrapper.eq("GWAA001", user.getACCOUNT());
            GwaaT gwaaT = gwaaTMapper.selectOne(wrapper);
            inDto.put("GWAA001", user.getACCOUNT());
//            Dto dto = gwat300Service.getGwaa(inDto);
            if (gwaaT.getGWAA007().equals("0")) {
                list = gwat300Service.getGwak1Page(wapper.getPage(),inDto);
            } else if (gwaaT.getGWAA007().equals("1")) {
                list = gwat300Service.getGwak2Page(wapper.getPage(),inDto);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new SuccessResponseData(list);
    }

//
    /**
     * 购物车-订单修改
     *
     * @return
     */
    @RequestMapping(value = "updateOrder")
    public ResponseData updateOrder(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser user = wapper.getSysUser();
        List<GwcqT> gwcq_tPOs = new ArrayList<>();
        List<GwcnT> gwcn_tPOs = new ArrayList<>();
        try {
            JSONArray orders = JSONArray.parseArray(inDto.getString("obj"));

            for (int i = 0, j = orders.size(); i < j; i++) {
                JSONObject item = orders.getJSONObject(i);
                GwcqT gwcq_tPO = CommonUtils.toJavaClass(item,GwcqT.class);
                gwcq_tPO.setGWCQENT(user.getDBC());
                gwcq_tPO.setGWCQ005(item.getBigDecimal("GWCQ003").multiply(item.getBigDecimal("GWCQ004")));
                gwcq_tPOs.add(gwcq_tPO);
            }
            gwat300Service.updateGwcq(gwcq_tPOs);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error("服务开小差了");
        }
        return ResponseData.success();
    }

    /**
     * 根据区域范围获取经销商
     *
     * @return
     */
    @RequestMapping(value = "getGwak")
    public ResponseData getGwak(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        try {
            inDto.put("gwaklent", inDto.getString("ENT"));
            list = gwat300Service.getGwak(inDto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.success(list);
    }

    /**
     * 删除暂存
     *
     * @return
     */
    @RequestMapping("delete")
    public ResponseData delete(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        try {
            inDto.put("GWCQENT", inDto.getString("ENT"));
            gwat300Service.delete(inDto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.success();
    }

    /**
     * 获取当前商品在制数量等信息
     *
     * @return
     */
    @RequestMapping(value = "getGwcxData")
    public ResponseData getGwcxData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto list = gwat300Service.getGwcxData(inDto);
        if (list==null){
            list = new Dto();
        }
        if (list.size() == 0) {
            list.put("GWCX005", "0");
            list.put("GWCX006", "0");
            list.put("GWCX007", "0");
            list.put("GWCX008", "0");
        }
        return ResponseData.success(list);
    }
//
    /**
     * 获取转单潜在商机列表
     *
     * @return
     * @author wenchuan.li on 2018/07/19 16:00
     */
    @ResponseBody
    @RequestMapping(value = "getQzsjList")
    public ResponseData getQzsjList(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser user = wapper.getSysUser();
        try {

            inDto.put("GWBKENT", inDto.getString("ENT"));
            inDto.put("GWBKUSER", user.getID());

        } catch (Exception e) {

            e.printStackTrace();
            return new ErrorResponseData();
        }
        return new SuccessResponseData(gwat300Service.getQzsjList(inDto));
    }

    /**
     * 潜在意向转单--提交
     *
     * @return
     * @author wenchuan.li on 2018/07/20 09:53
     */
    @RequestMapping(value = "qzyxzdSubmit")
    public ResponseData qzyxzdSubmit(@DtoParam DtoWapper wapper) {
        Date date = new Date();
        Dto inDto = wapper.getDto();

        List<GwcqT> gwcq_tPOs = new ArrayList<>();
        List<GwbkT> gwbk_tPOs = new ArrayList<>();
        GwbhT gwbh_tPO = new GwbhT();
        Dto gwbk_tPOx = Dtos.newDto();
        SysUser currentUser = wapper.getSysUser();
        try {

            JSONArray orders = JSONArray.parseArray(inDto.getString("objs"));
            String no = "GWDD" + DateUtils.getDate("yyyyMMddHHmmssSSS");

            Dto gwbhDto = Dtos.newDto();
            gwbhDto.put("GWBHENT", inDto.getString("ENT"));
            gwbhDto.put("GWBHNAME", inDto.getString("GWBKNAME"));
            gwbhDto.put("GWBHID", inDto.getString("GWBKID"));
            List<Dto> gwbhList = gwat161Service.getGwbhListByGwbhname(gwbhDto);
            Dto gwbhNewDto = gwbhList.get(0);
            gwbh_tPO = CommonUtils.toJavaClass(gwbhNewDto,GwbhT.class);
            // 购物车从潜在商机转单成功后自动新增一笔拜访记录，状态为“S.已成交”；
            // 取消转单则自动删除状态为“S.已成交”的拜访记录
            gwbh_tPO.setGWBHSEQ(gwbh_tPO.getGWBHSEQ().add(BigDecimal.ONE));
            gwbh_tPO.setGWBH003(LocalDate.now());//拜访日期
            gwbh_tPO.setGWBH028("Z");//成交结案
            gwbh_tPO.setGWBHACTI("S");

            // 取折扣率
            // GWAK056为空 就取 客户分类表的折扣率，如果没有就默认1
            BigDecimal gwak56 = inDto.getBigDecimal("GWAK056");
            if (gwak56 == null || gwak56 == BigDecimal.ZERO) {
                gwak56 = BigDecimal.ONE;
                String GWAK009 = inDto.getString("GWAK009");
                if (ToolUtil.isNotEmpty(GWAK009) && !GWAK009.equals("*")) {
                    QueryWrapper<GwafT> wrapper = new QueryWrapper<>();
                    wrapper.eq("GWAFENT",inDto.getString("ENT"));
                    wrapper.eq("GWAF001",GWAK009);
                    GwafT gwaf_tPO = new GwafT().selectOne(wrapper);
                    if (gwaf_tPO != null && gwaf_tPO.getGWAF004() != null) {
                        gwak56 = new BigDecimal(gwaf_tPO.getGWAF004());
                    }
                }
            }

            for (int i = 0, j = orders.size(); i < j; i++) {
                JSONObject item = orders.getJSONObject(i);
                Dto inDto2 = Dtos.newDto();
                inDto2.put("GWBGENT", currentUser.getDBC());
                inDto2.put("GWBG001", item.getString("GWBKNAME"));
                inDto2.put("GWBG002", item.getString("GWBKID"));
                Dto gwbgDto = gwat300Service.getGwbg(inDto2);
                if(ToolUtil.isEmpty(gwbgDto)){
                    return new ErrorResponseData("缺少归属业务员");
                }
                //潜在商机明细
                GwcqT gwcq_tPO = new GwcqT();
                gwcq_tPO.setGWCQENT(currentUser.getDBC());
                gwcq_tPO.setGWCQDOCNO(no);
                gwcq_tPO.setGWCQSEQ(BigDecimal.valueOf(i + 1));
                gwcq_tPO.setGWCQDOCDATE(LocalDate.now());
                gwcq_tPO.setGWCQ001(item.getString("GWBK001"));
                gwcq_tPO.setGWCQ002(item.getString("GWBK002")); // 销售单位
                gwcq_tPO.setGWCQ003(item.getBigDecimal("GWBK003"));
                gwcq_tPO.setGWCQ004(item.getBigDecimal("GWBK004"));//是实际价格
                gwcq_tPO.setGWCQ005(item.getBigDecimal("GWBK003").multiply(item.getBigDecimal("GWBK004")));
                gwcq_tPO.setGWCQ014(gwbgDto.getString("GWBG005"));
                // update by wenchuan.li 2018-10-31 16:02
                // GWCQ006/GWCQ007的值改存到GWCQ107/GWCQ108
                gwcq_tPO.setGWCQ006(item.getString("GWAK008"));//币别
                gwcq_tPO.setGWCQ107(item.getString("GWAK017"));
                gwcq_tPO.setGWCQ108(item.getString("GWAK018"));

                gwcq_tPO.setGWCQ008(item.getString("GWAK031"));//TODO这里是不是应该抓取 客户联系人表里面的默认联系人
                gwcq_tPO.setGWCQ009(item.getString("GWAK030"));
                gwcq_tPO.setGWCQ010(item.getString("GWBKID"));

                //经销商信息
                Dto gwbh016Dto = Dtos.newDto();
                gwbh016Dto.put("GWBHENT", inDto.getString("ENT"));
                //gwbh016Dto.put("gwbhacti", "Y");
                gwbh016Dto.put("GWBHNAME", item.getString("GWBKNAME"));
                gwbh016Dto.put("GWBHID", item.getString("GWBKID"));
                List<Dto> gwbh016List = gwat300Service.getJxsByGwbh016(gwbh016Dto);
                if (ToolUtil.isNotEmpty(gwbh016List)) {
                    gwbh016Dto = gwbh016List.get(0);
                    gwcq_tPO.setGWCQ011(gwbh016Dto.getString("gwbh016"));
                    gwcq_tPO.setGWCQ012(gwbh016Dto.getString("GWAK031"));
                    gwcq_tPO.setGWCQ013(gwbh016Dto.getString("GWAK030"));
                }

                gwcq_tPO.setGWCQ020(item.getString("GWAK028"));
                gwcq_tPO.setGWCQ021(item.getString("GWAK020"));
                gwcq_tPO.setGWCQ022(item.getString("GWAK021"));
                gwcq_tPO.setGWCQ023(item.getString("GWAK022"));
                gwcq_tPO.setGWCQ024(item.getString("GWAK023"));
                gwcq_tPO.setGWCQ025(item.getString("GWAK024"));
                gwcq_tPO.setGWCQ026(item.getString("GWAK025"));
                //gwcq_tPO.setGWCQ027(item.getString("gwco027"));
                //gwcq_tPO.setGWCQ028(item.getString("gwco028"));
                gwcq_tPO.setGWCQ030(item.getString("GWBKNAME"));
                gwcq_tPO.setGWCQ031(item.getBigDecimal("GWBKSEQ"));

                //add by wenchuan.li 2018/09/29 17:47
                // 预计购买日期\预计回款日期
                gwcq_tPO.setGWCQ101(item.getString("GWBK008"));
                gwcq_tPO.setGWCQ102(item.getString("GWBK009"));

                //add by wenchuan.li 2018/10/27 16:33
                gwcq_tPO.setGWCQ103(gwak56);//折扣率
                gwcq_tPO.setGWCQ104(gwak56.multiply(gwcq_tPO.getGWCQ005()));//折扣后金额

                SysOrg sys_orgPO = sysOrgMapper.selectById(inDto.getString("GWAKPLANT"));
                if (ToolUtil.isNotEmpty(sys_orgPO)) {
                    gwcq_tPO.setGWCQLEGAL(sys_orgPO.getBIZ_CODE());//ERP组织
                    gwcq_tPO.setGWCQPLANT(sys_orgPO.getBIZ_CODE());//ERP运营中心
                }
                gwcq_tPO.setGWCQMLEGAL(inDto.getString("GWAKPLANT"));//归属法人

                gwcq_tPO.setGWCQACTI("Y");
                gwcq_tPO.setGWCQUSER(currentUser.getID());
                gwcq_tPO.setGWCQGRUP(currentUser.getORG_ID());
                gwcq_tPO.setGWCQTIME(DateUtils.formatDate(date, DateUtils.PATTERN_HH_mm_ss));
                gwcq_tPO.setGWCQDATE(LocalDate.now());
                gwcq_tPO.setGWCQORIU(currentUser.getID());
                gwcq_tPO.setGWCQORIG(currentUser.getORG_ID());
                gwcq_tPOs.add(gwcq_tPO);

                // 拜访记录--商品需求明细
                // bug修正，由修改商品改出新生成商品
                // update by wenchuan.li 2018/10/14 20:20
                GwbkT gwbk_tPO = new GwbkT();
                gwbk_tPO.setGWBKENT(currentUser.getDBC());
                gwbk_tPO.setGWBKNAME(item.getString("GWBKNAME"));
                gwbk_tPO.setGWBKID(item.getString("GWBKID"));
                gwbk_tPO.setGWBKSEQ(item.getBigDecimal("GWBKSEQ"));
                gwbk_tPO.setGWBKSEQ2(gwbh_tPO.getGWBHSEQ());
                gwbk_tPO.setGWBK001(item.getString("GWBK001"));
                gwbk_tPO.setGWBK002(item.getString("GWBK002")); // 销售单位
                gwbk_tPO.setGWBK003(item.getBigDecimal("GWBK003"));
                gwbk_tPO.setGWBK004(item.getBigDecimal("GWBK004"));
                gwbk_tPO.setGWBK005(item.getBigDecimal("GWBK003").multiply(item.getBigDecimal("GWBK004")));

                gwbk_tPO.setGWBK008(item.getString("GWBK008"));
                gwbk_tPO.setGWBK009(item.getString("GWBK009"));
                gwbk_tPO.setGWBKACTI("Z");
                gwbk_tPO.setGWBKTIME(DateUtils.getTime());
                gwbk_tPO.setGWBKDATE(LocalDate.now());
                gwbk_tPO.setGWBKORIG(currentUser.getORG_ID());
                gwbk_tPO.setGWBKUSER(currentUser.getID());
                gwbk_tPO.setGWBKORIU(currentUser.getID());
                gwbk_tPOs.add(gwbk_tPO);
            }

            // 拜访记录--商品需求明细--全部修改成setGwbkacti =x
            // bug修正，由于每个提单对应各自的商品，故不用修改前已提单的状态
            // update by wenchuan.li 2018/10/14 20:20
            //gwbk_tPOx.put("GWBKNAME", inDto.getString("GWBKNAME"));
            //gwbk_tPOx.put("GWBKID", inDto.getString("GWBKID"));
            //gwbk_tPOx.put("GWBKSEQ2",gwbh_tPO.getGwbhseq());
            //gwbk_tPOx.put("gwbkoriu", currentUser.getId_());


            gwat300Service.saveZdData(gwcq_tPOs, gwbk_tPOs, gwbh_tPO, gwbk_tPOx);
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("系统出小差了");
        }
        return new SuccessResponseData();
    }

    /**
     * 获取经销商信息
     *
     * @return
     */
    @RequestMapping(value = "getJxsPage")
    public ResponseData getJxsPage(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser currentUser = wapper.getSysUser();
        List<Dto> list = new ArrayList<>();
        try {
            //客户权限
            inDto.put("GWAK006", "2");
            Dto gwb001 = gwbService.getGwb001(currentUser,inDto);
            inDto.put("CUSTOMERS", gwb001.get("CUSTOMERS"));

            inDto.put("GWAK019", currentUser.getACCOUNT());
            list = gwat300Service.getJxsPage(wapper.getPage(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new SuccessResponseData(list);
    }

    /**
     * 获取归属法人（公司）列表
     *
     * @author wenchuan.li 2018/09/28 16:43.
     */
    @RequestMapping(value = "getSys001")
    @ResponseBody
    public ResponseData getSys001(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        try {
            return new SuccessResponseData(systemService.getSys001(inDto));
        } catch (Exception e) {
            return new ErrorResponseData("系统出小差了");
        }

    }
}
